home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / security / doc / clippings / 910801-01 < prev    next >
Encoding:
Internet Message Format  |  1991-09-12  |  7.9 KB

  1. From: tchrist@convex.COM (Tom Christiansen)
  2. Newsgroups: comp.unix.questions,alt.security
  3. Subject: Re: do's and don'ts with setuid stuff??
  4. Message-ID: <1991Aug01.175624.21612@convex.com>
  5. Date: 1 Aug 91 17:56:24 GMT
  6. References: <12569@ibism.uucp>
  7. Organization: CONVEX Software Development, Richardson, TX
  8.  
  9. >From the keyboard of rwu@ibism.UUCP (Raymond Wu):
  10. :Hello netters...
  11. :
  12. :We're contemplating writing our version of passwd which will enforce
  13. :the compliance of passwords to our corporate security standards - such as not being in a dictionary, min/max legnths, patterns, etc.
  14. :
  15. :Being new to the Un*x world, I see several ways of implementing this - writing setuid scripts incorporating calls to crypt and awk to effect new passwords or
  16. :writing setuid code to effect the change of the passwd / passwd.adjunct files - replacing the passwd utility.
  17. :
  18. :What are the (dis)advantages/hazards/risks of doing it either way?
  19. :
  20. :I heard somewhere that setuid scripts represents a major security hole in that a setuid script can be interrupted in such a manner that another non-setuid script can be executed in this place....??
  21.  
  22. PLEASE PUT THIS ON THE FAQ AND PUT IT TO REST.
  23.  
  24. You can't make suid shell script secure.  Only a fix to the kernel will do this.
  25.  
  26. Awk and crypt?  You've got to be kidding.
  27.  
  28. You should look at Larry Wall's passwd program.  It probably does all you want.
  29.  
  30. And please use carriage returns.
  31.  
  32. Here's an old posting of mine (plus someone else's) about this.  
  33.  
  34. --tom
  35.  
  36.  
  37. When you execute a shell script, what really happens is that the kernel
  38. opens the file you asked it to run, sees the magic number of "#!", and
  39. then calls the interpreter following that to run the script for you.
  40. The problem is that it passes the name of the script to the shell, and
  41. the shell must then reopen the script.  That means we opened the script
  42. twice.
  43.  
  44. Consider the following scenario:  /usr/local/bin/zot is a suid shell
  45. script.  ~/snark is a symlink pointing to zot.  ~/gotcha is some
  46. program that if run as root would compromise security, such as by
  47. giving me a root shell.
  48.  
  49. I type something like "nice +64 snark &" and let the kernel ever so
  50. slowly decide to call the shell with an argument of snark.  It's
  51. already set the euid to root because it's pointing to zot, which is
  52. suid root.  Now the shell ever so slowly starts up.  In the meantime, I
  53. make snark point not to zot but to gotcha.  Bingo!  By the time the
  54. suid shell opens snark, it gets gotcha instead of zot, and the whole
  55. system is down the tubes.
  56.  
  57. As you see, the presence of ANY suid script on a system allows anyone
  58. to run anything as root.  This is obviously a very bad thing.
  59.  
  60. Now, if the suid script is in perl or ksh, they should keep working
  61. because these programs have alternate versions of themselves (suidperl
  62. and suid_exec) installed suid for just this reason.  (Theoretically --
  63. last I checked suid_exec wasn't installed right.) Csh and sh scripts,
  64. however, will not work.
  65.  
  66. Several work-arounds exist.  It's bad to have a suid script anyway, but
  67. if you really must, then you're going to have to make a C wrapper
  68. around it that sets the uids the way you want them and then invokes the
  69. shell.  The easiest way to do this is using the op utility, which was
  70. designed for this very thing.  See the alt.sources posting, or mail me.
  71.  
  72.  
  73. Here is an additional posting on the subject.  Even wrappers don't get
  74. around these problems.  I'd never trust a shell to run anything with
  75. euid != uid.  Maybe perl; taintperl is pretty clever.
  76.  
  77.  
  78. --tom
  79.  
  80. ------- Forwarded Message
  81.  
  82. Date:         10 Aug 90 19:41:32 GMT
  83. From:         vlb@magic.apple.com (Vicki Brown)
  84. Subject:      Re: Suid script security
  85. Organization: Apple Computer
  86. Newsgroups:   comp.unix.questions
  87.  
  88.  
  89. In article <14920003@hpdmd48.boi.hp.com> markw@hpdmd48.boi.hp.com (Mark Wolfe) writes:
  90. >
  91. >    I know that suid scripts are a bad idea from reading comp.questions and
  92. >comp.wizards over the last year or so. It seems that just about every guru
  93. >in the world has posted a warning NOT to do it, so I decided I would follow
  94. >the advice (it's a rare subject that all guru's agree on). However, it appears
  95. >that I'm now about to have one of these ugly animals forced on me from above,
  96. >so I'd like some advice:
  97. >
  98. > 1)  Just what are the security risks involved? (i.e. how would someone attack
  99. >     a system via one of these).
  100. >
  101. > 2)  What can I do to make this as secure as possible?
  102.  
  103. Warning - very long response ahead.  Proceed at your own risk.
  104.  
  105. There was a very interesting paper in the USENIX Association's publication,
  106.  ;login: ( "How To Write a Setuid Program", Matt Bishop, ;login:
  107. Vol 12, Number 1, January/February 1987).  An excerpt:
  108.     
  109.     Some versions of UNIX allow command scripts, such as shell scripts,
  110.     to be made setuid ... Unfortunately, given the power and complexity
  111.     of many command interpreters, it is often possible to force them to
  112.     perform actions which were not intended, and which allow the user to
  113.     violate system security.  This leaves the owner of the setuid script
  114.     open to a devastating attack.  In general, such scripts should be avoided.
  115.  
  116.     ... suppose a site has a setuid script of sh commands.  An attacker
  117.     simply executes the script in such a way that the shell ... appears
  118.     to have been invoked by a person logging in.  UNIX applies the setuid
  119.     bit on the script to the shell, and ... it becomes interactive...
  120.  
  121.     One way to avoid having a setuid script is to turn off the setuid
  122.     bit on the script, and ... use a setuid [binary] program to invoke it.
  123.     This program should take care to call the command interpreter by its full
  124.     path name, and reset environment information such as file descriptors
  125.     and environment variables to a known state.   However, this method
  126.     should be used only as a last resort and as a temporary measure,
  127.     since with many command interpreters it is possible even under these
  128.     conditions to force them to take undesirable action.
  129.  
  130. The biggest problem with shell scripts is that you (the programmer /
  131. administrator) have very little control over the programs which run within
  132. the script.  As a very real example, I ran across a script which allowed
  133. users to enter bug reports, using the "vi" editor.  The script was
  134. setuid root, because it wanted to save files in funny places.  The programmer
  135. had guarded against shell escapes (a known feature of vi), by making this
  136. script the login shell.  However, he couldn't guard against another feature
  137.     :e /etc/passwd
  138.  
  139. You can attempt to make your script as safe as possible by
  140.     1) being very restrictive in your choice of UID.  That is,
  141.        make the script setuid for a non-privileged user, rather than root
  142.        (for example, if it must write a log file, could the log file
  143.        live in some locked area, accessed only by a new and otherwise
  144.        non-privileged account?)
  145.     2) making the script setgid rather than setuid, with a very
  146.        restricted GID (see #1)
  147.     3) ensuring that the script is short, very simple, and does not
  148.        make use of commands such as `vi', `mail' or anything interactive.
  149.        setuid programs should do ONE thing only, and in a non-complex
  150.        manner.
  151.     4) setting the PATH, IFS, and other environment variables explicitly
  152.        within the script
  153.     5) locking down the permissions on the script.  If possible allow it
  154.        to be run only by group members.  Never allow write permission.
  155.     6) If your version of UNIX permits, take away read permission for
  156.        anyone other than the owner.  It's a bit harder to break
  157.        something if you can't see how it works.
  158.     7) Rewrite it in C (carefully)
  159.     8) Convince your management that they don't really need this.
  160.  
  161. If you plan to keep the script, or re-write it, try and get a copy of the
  162. paper.  If you can't find it, send me mail.
  163.    Vicki Brown   A/UX Development Group        Apple Computer, Inc.
  164.    Internet: vlb@apple.com            MS 58A, 10440 Bubb Rd.    
  165.    UUCP: {sun,amdahl,decwrl}!apple!vlb        Cupertino, CA  95014 USA
  166.               Ooit'n Normaal Mens Ontmoet?  En..., Beviel't?
  167.           (Did you ever meet a normal person?  Did you enjoy it?)
  168.  
  169. ------- End of Forwarded Message
  170.  
  171.